using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;

namespace My.IdlConverter.Core.Parsers
{
    public class InterfacePreprocessor : PreprocessorBase<string>
    {
        public readonly static string MultiNoteRegex = @"/\*!.*?\*/";
        public readonly static string SingleNoteRegex = @"//.*";

         public InterfacePreprocessor()
        {
        }

        public InterfacePreprocessor(string consumer)
            :base(consumer)
        {
        }

        public override string Process()
        {
            string content = Consumer;

            DeleteContent(SingleNoteRegex, RegexOptions.Multiline, ref content);
            DeleteContent(MultiNoteRegex, RegexOptions.Singleline, ref content);

            return content;
        }

        protected virtual void DeleteContent(string regexString, RegexOptions options, ref string content)
        {
            Regex reg = new Regex(regexString, options);
            if (reg.IsMatch(content))
            {
                MatchCollection matchCol = reg.Matches(content);
                foreach (Match nextMatch in matchCol)
                {
                    content = content.Replace(nextMatch.Value, "");
                }
            }
        }
    }
}
